<template>
  <!-- 系统设置模块-批处理控制-->
  <div class="fillcontain">
    <!-- 标题 -->
    <div class="fastQuery">
      <el-row>
        <el-col :span="6" class="common-box">
          <el-col :span="10" class="common-lab">
            <label class="labelName">业务分类</label>
          </el-col>
          <el-col :span="14">
            <el-input clearable v-model="sbusitype" disabled placeholder=""></el-input>
          </el-col>
        </el-col>
        <el-col :span="6" class="text_center">
          <el-button type="primary" icon="el-icon-search" @click="getBatchConsoleList"></el-button>
          <el-button type="primary" plain icon="el-icon-refresh" @click="resetSearch"></el-button>
        </el-col>
      </el-row>
    </div>
        <div class="contain"> 
            <div class="table_container">
            <!-- <el-row > 
                <el-col :span="24" class="pb15 pt15">
                    <el-button @click="showEdit(null)" type="danger" plain>增加</el-button>
                </el-col>
            </el-row> -->
            <el-table
                :data="batchConList"
                highlight-current-row
                header-cell-class-name="table-header-class"
                style="width:100%">
                    <el-table-column property="sparamid" label="业务编码"></el-table-column>
                    <el-table-column min-width="120" property="sdesc" label="业务描述"></el-table-column>
                    <!-- <el-table-column property="SvalueInfo" label="受理号"></el-table-column>
                    <el-table-column property="branchInfo" label="机构"></el-table-column> -->
                    <el-table-column 
                      property="svalue" 
                      label="SVALUE">
                      </el-table-column>
                    <el-table-column
                        fixed="right"
                        label="操作"
                        align='center'>
                    <template slot-scope="scope">
                        <span class="operationIcon" @click="showEdit(scope.row)">
                            <el-tooltip class="item" effect="light" content="编辑" placement="top">
                                <i class="el-icon-document"></i>
                            </el-tooltip>
                        </span>
                        <!--
                        <span @click="delBatchCon(scope.$index, scope.row)" class="operationIcon">
                            <el-tooltip  class="item" effect="light" content="删除" placement="top">
                                <i class="el-icon-delete"></i>
                            </el-tooltip>
                        </span>-->
                    </template>
                </el-table-column>
            </el-table>
            <el-row>
                <el-col :span="24">
                    <div class="pagination">
                        <el-pagination
                            background
                            v-if='paginations.total > 0'
                            :page-sizes="paginations.pageSizes"
                            :page-size="paginations.pageSize"
                            :layout="paginations.layout"
                            :total="paginations.total"
                            :current-page='paginations.pageIndex'
                            @current-change='handleCurrentChange'
                            @size-change='handleSizeChange'>
                        </el-pagination>
                    </div>
                </el-col>
            </el-row>
        </div>    
    </div>
    <!-- 弹窗 -->
    <el-dialog title="编辑" 
        :close-on-press-escape = "false"
        :close-on-click-modal = "false"
        :visible.sync="dialogFormVisible" 
        width="60%" center>
        <el-form  label-width="100px" class="search_container">
            <el-row>
                <el-col :span="21">
                    <el-form-item label="业务编号">
                        <el-input disabled v-model="batchConsole.sparamid"></el-input>
                    </el-form-item>
                </el-col>
             </el-row>
             <el-row>     
                <el-col :span="21">
                    <el-form-item label="业务描述">
                        <el-input v-model="batchConsole.sdesc" :maxlength="30"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="20">
                    <el-form-item label="svalue">
                        <el-input v-model="batchConsole.svalue"
                            disabled type="textarea" :rows="8" resize="none">></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="4">
                    <el-button icon="el-icon-plus" @click="editSvalueInfo" plain circle></el-button>
                    <el-button icon="el-icon-delete" @click="removeSvalueInfo" plain circle></el-button>
                </el-col>
            </el-row>
            <!--
            <el-row>        
                <el-col :span="20">
                    <el-form-item label="机构">
                        <el-input v-model="batchConsole.branchInfo"
                            disabled type="textarea" :rows="8" resize="none"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="4">
                    <el-button icon="el-icon-plus" @click="editBranchInfo" plain circle></el-button>
                    <el-button icon="el-icon-minus" @click="removeBranchInfo" plain circle></el-button>
                </el-col>
            </el-row>
            -->
            <!-- <el-row>          
                <el-col :span="12">
                    <el-form-item label="业务状态">
                        <el-select v-model="batchConsole.businessStatus" placeholder="">
                            <el-option value="0" label="关闭"></el-option>
                            <el-option value="1" label="开启"></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>  -->
        </el-form>      
        <div slot="footer" class="dialog-footer">
            <el-button @click="edit">保存</el-button>
        </div>
    </el-dialog>
    <!-- 弹窗 -->
    <el-dialog title="value将以逗号拼接" 
        :close-on-press-escape = "false"
        :close-on-click-modal = "false"
        :visible.sync="dialogSvalueFormVisible" 
        width="50%" center>
        <el-row > 
            <el-col :span="24" class="pb15 pt15">
                <el-button @click="addSvalue" type="danger" plain>增加</el-button>
            </el-col>
        </el-row>
        <el-table
            :data="svalueList"
            highlight-current-row
            header-cell-class-name="table-header-class"
            max-height="350"
            style="width:100%">
            <el-table-column 
              property="value" 
              label="value">
              <template slot-scope="scope">
                   <el-input v-model="scope.row.value" />
              </template>
            </el-table-column>
            <el-table-column
                width="280"
                fixed="right"
                label="操作"
                align='center'>
                <template slot-scope="scope">
                    <span class="operationIcon"
                        @click="removeSvalue(scope.$index, scope.row)">
                        <el-tooltip :disabled="scope.$index == 0" class="item" effect="light" content="删除" >
                            <i class="el-icon-delete"></i>
                        </el-tooltip>
                    </span>
                </template>
            </el-table-column>
            </el-table>
        </el-form>      
        <div slot="footer" class="dialog-footer">
            <el-button @click="listSvalue">确定</el-button>
        </div>
    </el-dialog>
    <!-- 弹窗 -->
    <!-- <el-dialog title="编辑机构" 
        :close-on-press-escape = "false"
        :close-on-click-modal = "false"
        :visible.sync="dialogBranchFormVisible" 
        width="50%" center>
        <el-row > 
            <el-col :span="24" class="pb15 pt15">
                <el-button @click="addBranch" type="danger" plain>增加</el-button>
            </el-col>
        </el-row>
        <el-table
            :data="branchList"
            highlight-current-row
            header-cell-class-name="table-header-class"
            max-height="350"
            style="width:100%">
            <el-table-column 
              property="branch" 
              label="机构">
              <template slot-scope="scope">
                  <el-input v-model="scope.row.branch" :maxlength="3"/>
              </template>
            </el-table-column>
            <el-table-column
                fixed="right"
                label="操作"
                align='center'>
                <template slot-scope="scope">
                    <span class="operationIcon"
                        @click="removeBranch(scope.$index, scope.row)">
                        <el-tooltip class="item" effect="light" content="删除" >
                            <i class="el-icon-minus"></i>
                        </el-tooltip>
                    </span>
                </template>
            </el-table-column>
            </el-table>
        </el-form>      
        <div slot="footer" class="dialog-footer">
            <el-button @click="listBranch">确定</el-button>
        </div>
    </el-dialog> -->
  </div>
</template>
<script>
  import {
    getBatchConsoleList,
    batchConsoleEdit
  } from "@/api/setting";
  import constant from "@/utils/constant";
  import {Message, MessageBox} from 'element-ui';
  export default {
    data() {
      return {
        batchConList: [],
        batchConsole: {sparamid:'',sdesc:'',svalue:''},
        dialogFormVisible: false,
        dialogSvalueFormVisible: false,
        dialogBranchFormVisible: false,
        svalueList: [],
        sbusitype: 'ILMP_BAT',
        //需要给分页组件传的信息
        paginations: {
          total: 0,        // 总数
          pageIndex: 1,  // 当前位于哪页
          pageSize: 10,   // 1页显示多少条
          pageSizes: [5, 10, 15, 20],  //每页显示多少条
          layout: "total, sizes, prev, pager, next, jumper",   // 翻页属性
        },
      }
    },
    created() {
      
    },
    mounted() {
      this.getBatchConsoleList();
    },
    methods: {
      resetSearch(){
        //  this.sbusitype = '';
      },
      getBatchConsoleList(){
        this.$store.dispatch('loading/CHNAGE_SUBLOADING',true);
        let para = {
            pageNumber: this.paginations.pageIndex,
            pageSize: this.paginations.pageSize,
            sbusitype: this.sbusitype,
            // businessDesc: this.businessDesc
        };
        this.batchConList = [];
        getBatchConsoleList(para).then(res =>{
            if(res.resultCode == constant.SUCCESS){
                this.paginations.total = res.data.total;
                let list = res.data.list;
                this.batchConList = list;
                // for(let i = i ; i < list.length; i++){
                //     let sspl = list[i];
                //     if(sspl.sparamid == this.nb_onoff
                //       ||sspl.sparamid == this.in_onoff
                //       ||sspl.sparamid == this.ren_onoff){
                //         if(sspl.sparamid == this.nb_onoff){
                //           for(let j = 0 ; j < list.length; j++){
                //             let val = list[i];
                //             if(sspl.sparamid == 'ilmp_maintain_batch_nb_applnum'){
                //                 sspl.applnumInfo = val.svalue;
                //             }
                //             if(sspl.sparamid == 'ilmp_maintain_batch_nb_company'){
                //                 sspl.branchInfo = val.svalue;
                //             }
                //           }
                //         }
                //         this.batchConList.push(sspl);
                //     }
                // }
                this.$store.dispatch('loading/CHNAGE_SUBLOADING',false);
            }
        }).catch(err =>{
            console.log(err);
            this.$store.dispatch('loading/CHNAGE_SUBLOADING',false);
        })
      },
      edit(){
          this.$store.dispatch('loading/CHNAGE_SUBLOADING',true);
		  // //验证环境--保存的时候人为加一个不存在的受理号，使捞数卡死 csf
		  // //卡受理号
		  // if(this.batchConsole.sparamid =="ilmp_maintain_batch_nb_applnum") {
			 //  if(this.batchConsole.svalue.indexOf("xxxxyyyy") <0){
			 //  			  if (this.batchConsole.svalue == "" ||this.batchConsole.svalue ==undefined){
			 //  				  this.batchConsole.svalue = "xxxxyyyy";
			 //  			  }else {
			 //  				  let tmp = "xxxxyyyy"+","+this.batchConsole.svalue;
			 //  				  this.batchConsole.svalue = tmp;
			 //  			  }
			 //  }
		  // }
		    //验证环境--保存的时候人为加一个不存在的受理号，使捞数卡死 csf
          let para = this.batchConsole;
		  
		  
          batchConsoleEdit(para).then(res =>{
            if(res.resultCode == constant.SUCCESS){
                this.$message({
                  message: '编辑成功！',
                  type: 'success'
                });
                this.dialogFormVisible = false;
                this.getBatchConsoleList();
            }
            this.$store.dispatch('loading/CHNAGE_SUBLOADING',false);
          }).catch(err =>{
            console.log(err);
            this.$store.dispatch('loading/CHNAGE_SUBLOADING',false);
          })
      },
      showEdit(row){
          this.dialogFormVisible = true;
          // this.Ssplpf = {id:'',businessCode:'',businessDesc:'',applnumInfo:'',
          //                       branchInfo:'',businessStatus:'0',status:'0',createId:'',
          //                       createTime:'',lastUpdateId:'',lastUpdateTime:''};
          if(row != null){
              this.batchConsole.sparamid = row.sparamid;
              this.batchConsole.sdesc = row.sdesc;
              this.batchConsole.svalue = row.svalue;
          }
      },
      editSvalueInfo(){
          this.dialogSvalueFormVisible = true;
          this.svalueList = [];
          let svalueArr = this.batchConsole.svalue.split(',');
          for(let i = 0 ; i < svalueArr.length ; i++){
            if(svalueArr[i]){
               let data = {value:svalueArr[i]};
               this.svalueList.push(data);
            }
          }
      },
      // editBranchInfo(){
      //     this.dialogBranchFormVisible = true;
      //     this.branchList = [];
      //     let branchArr = this.batchConsole.branchInfo.split(',');
      //     for(let i = 0 ; i < branchArr.length ; i++){
      //       if(branchArr[i]){
      //          let data = {branch:branchArr[i]};
      //          this.branchList.push(data);
      //       }
      //     }
      // },
      removeSvalueInfo(){
        MessageBox.confirm('清空值确认？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
            this.batchConsole.svalue = '';
        });
      },
      // removeBranchInfo(){
      //     this.$confirm('清空机构？')
      //     .then(_ => {
      //       this.batchConsole.branchInfo = '';
      //     }).catch(_ => {});
      // },
      addSvalue(){
          let data = {value:''};
          this.svalueList.push(data);
      },
      removeSvalue(index,row){
          this.svalueList.splice(index,1);
      },
      listSvalue(){
          this.dialogSvalueFormVisible = false;
          let svalueStr = '';
          for(let i = 0 ; i < this.svalueList.length ; i++){
            let value = this.svalueList[i].value;
            if(value){
                svalueStr += value + ',';
            }
          }
          if(svalueStr.length > 0){
             svalueStr = svalueStr.substring(0,svalueStr.length - 1);
          }
          this.batchConsole.svalue = svalueStr;
      },
      // addBranch(){
      //     let data = {branch:''};
      //     this.branchList.push(data);
      // },
      // removeBranch(index,row){
      //     this.branchList.splice(index,1);
      // },
      // listBranch(){
      //     this.dialogBranchFormVisible = false;
      //     let branchStr = '';
      //     for(let i = 0 ; i < this.branchList.length ; i++){
      //       let branch = this.branchList[i].branch;
      //       if(branch){
      //           branchStr += branch + ',';
      //       }
      //     }
      //     if(branchStr.length > 0){
      //        branchStr = branchStr.substring(0,branchStr.length - 1);
      //     }
      //     this.batchConsole.branchInfo = branchStr;
      // },
      // 每页多少条切换
      handleSizeChange(pageSize) {
        this.paginations.pageIndex = 1;
        this.paginations.pageSize = pageSize;
        this.getBatchConsoleList();
      },
      // 上下分页
      handleCurrentChange(page) {
        this.paginations.pageIndex = page;
        this.getBatchConsoleList();
      }
    },
    computed: {},
  }
</script>
<style lang="less" scoped>
  .fillcontain {
    padding-bottom: 0;
    .fastQuery {
      padding: 15px 20px 10px 20px;
      background: #fff;
      border-bottom: 1px solid #e1e1e1;
      .fastQuery_title {
        color: #666;
        padding: 6px 0px;
      }
    }
  }

  .contain {
    background: #fff;
    padding: 10px;
    margin-bottom: 20px;
  }

  .pagination {
    padding: 10px 20px;
    text-align: right;
  }
</style>
